package com.xzj.common.secure.advice;

import com.xzj.common.secure.annotation.XzjEncrypt;
import com.xzj.common.secure.util.SecureAdviceUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * @program: xzj-common
 * @ClassName: EncryptRequestAdvice
 * @description: 接口请求参加密
 * @author: XiaZunJun
 * @create: 2024-08-05 17:08
 */
@RestControllerAdvice
@Slf4j
public class EncryptRequestAdvice  extends RequestBodyAdviceAdapter {
    @Override
    public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
        return methodParameter.hasMethodAnnotation(XzjEncrypt.class);
    }

    @Override
    public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
        return SecureAdviceUtil.requestAdviceBeforeRead(inputMessage, parameter,false);
    }
}
